#pragma once
#include<functional>
#include<list>
#include <Guid.hpp>
namespace xc{

    template<typename ...Args>
	class Event {
	protected:
		typedef std::function<void(Args...)> EventCallback;
	private:

		class Token {
		public:
			xg::Guid token;
			EventCallback callback;
		};


		std::list<Token> m_Events;
	public:
		virtual xg::Guid onTrigger(EventCallback c) {
			Token t;
			t.token = xg::newGuid();
			t.callback = c;
			m_Events.push_back(t);
			return t.token;
		}
		virtual void remove(xg::Guid id) {
			m_Events.remove_if([=](auto c1)->bool{
				return c1.token == id;
			});
		}
		virtual void broadcast(Args... args) {
			for (auto& e : m_Events) {
				e.callback(args...);
			}
		}
	};
}